import { useGlobalStore } from "../store/global"

export function registerDirective(app) {
    app.directive('permission', {
        mounted(el, binding) {
            const globalStore = useGlobalStore()
            const permissionData = globalStore.permissionData;
            const isButton = function findButton() {
                return permissionData.some(item => {
                    if (item.children) {
                        findButton(item.children)
                    }
                    return item.name == binding.value;
                })
            }

            if (!isButton) {
                el.disabled = true;   // 设置禁用功能
                el.classList.add('is-disabled'); // 添加禁用样式
            }
        },
    })
}